<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2018/11/18
 * Time: 21:38
 */

namespace app\storage\controller;

use app\storage\model\SeatModel;
use app\storage\service\CommonService;
use cmf\controller\AdminBaseController;
use think\Request;

class SeatController extends AdminBaseController
{
    private $seatModel;
    private $commonService;
    use \app\storage\util\Common;
    public function __construct( CommonService $commonService, SeatModel $seatModel,Request $request = null)
    {
        parent::__construct($request);
        $this->seatModel = $seatModel;
        $this->commonService = $commonService;
    }

    public function index()
    {
        $data = input();
        $shelfUuid = empty($data['shelfUuid']) ? '' : $data['shelfUuid'];
        $storageUuid = empty($data['storageUuid']) ? '' : $data['storageUuid'];
        $storageInfo = $this->commonService->get_assign_storage($storageUuid);
        $assign['shelfUuid'] = $shelfUuid;
        $assign['storageInfo'] = $storageInfo;
        $this->assign($assign);
        return $this->fetch('index');
    }

    public function getSeat()
    {
        $shelfUuid = input('shelfUuid');
        $storageUuid = input('storageUuid');
        $where = $this->getWhere();
        if ( !empty($shelfUuid)) {
            $where['where']['shelves_uuid'] = $shelfUuid;
        } else if (!empty($storageUuid)) {
            $where['where']['storage_uuid'] = $storageUuid;
        }
        $result = $this->seatModel->getSeat($where);
       // $result = $this->seatModel->getSeatByIsUsed($where);
        return json($result);
    }

    public function changeStatus()
    {
        $data = input('');
        $save['status']=$data['status'] == 0 ? 1 : 0;
        $result = $this->seatModel->isUpdate(true)->where('uuid',$data['uuid'])->update($save);
        ajax_response(boolval($result),'修改站位状态成功');
    }
}